<?php

namespace App\Http\Requests\App\V1\UserLogin;

use App\Http\Controllers\App\V1\ThirdPartyLoginController;
use App\Http\Requests\ApiRequest;
use App\Services\EasySms\AliSMSCountry;
use App\Services\OAuth\UserThirdPartyService;
use Illuminate\Http\UploadedFile;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\In;

/**
 * Class UserUpdateRequest
 *
 * @property string area_code
 * @property string phone
 * @property int|null sex
 *
 * @package App\Http\Requests\App\V1\User
 */
class UserLoginRequest extends ApiRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $dial_codes = array_column(AliSMSCountry::codeMap(), 'dial_code');
        
        $rule = [
            'phone'         => ['required_without:email', 'string', 'min:5', 'max:15'],
            'area_code'     => ['required_with:phone', 'string', Rule::in($dial_codes)],

            'email'         => ['required_without:phone', 'string', 'email'],

            'password'      => ['nullable', 'required_without:verify_code', 'string'],
            'verify_code'   => ['nullable', 'required_without:password', 'string', 'size:6'],

            // oauth bind rule
            'oauth_type'    => ['nullable', 'required_with:oauth_user_id', 'string', Rule::in(UserThirdPartyService::VALIDATE_OAUTH_TYPES)],
            'oauth_user_id' => ['nullable', 'required_with:oauth_type', 'int', 'min:1'],
        ];

        return $rule;
    }
}
